package com.lili.other;

import java.util.LinkedList;

/**
 * @Auther: 李 力
 * @Date: 2024/8/24
 * @Description: 155.最小栈 解法2
 * @version: 1.0
 */
public class MinStack2 {

    class Data {
        int val;
        int min;

        public Data(int val, int min) {
            this.val = val;
            this.min = min;
        }
    }

    //原始栈
    LinkedList<Data> stack = new LinkedList<>();

    public MinStack2() {

    }

    public void push(int val) {
        if (stack.isEmpty()) {
            stack.push(new Data(val, val));
        } else {
            stack.push(new Data(val, Math.min(val, stack.peek().min)));
        }
    }

    public void pop() {
        stack.pop();
    }

    public int top() {
        return stack.peek().val;
    }

    public int getMin() {
        return stack.peek().min;
    }
}
